import request from "@/utils/request";

const path = '/article'

/**
 * 文章相关接口
 */

// 上传图片
export const uploadImage = (formData) => {
  return request({
    url: path + `/article/uploadImage`, // 修改接口路径以匹配文件上传功能
    method: 'post',
    data: formData, // 使用formData替代原data对象
    headers: {
      // 设置正确的Content-Type以便服务器能识别这是个multipart/form-data请求
      'Content-Type': 'multipart/form-data'
    }
  })
}

// 修改文章
export const updateArticle = (id, data) => {
  return request({
    url: path + `/article/update/${id}`,
    method: 'put',
    data
  })
}

// 获取文章详情
export const getArticleApi = (id) => {
  return request({
    url: path + `/article/${id}`
  })
}

// 删除文章
export const delArticleApi = (id) => {
  return request({
    url: path + `/article/del/${id}`,
    method: 'delete'
  })
}

// 修改文章的状态
export const updateStatusApi = (id, status) => {
  return request({
    url: path + `/article/${id}/${status}`,
    method: 'put'
  })
}


// 查询所有的文章
export const getArticleList = (data) => {
  return request({
    url: path + '/article',
    method: 'post',
    data
  })
}

// 发布文章
export const releaseArticel = (data) => {
  return request({
    url: path + '/article/save',
    method: 'post',
    data
  })
}

// 获取文章分类和标签
export const getCategoryAndLabelList = () => {
  return request({
    url: path + `/article/basic`
  })
}

/**
 * 分类相关接口
 */

// 分类分页查询 
export const categoryPageList = (data) => {
  return request({
    url: path + `/category/${data.page}/${data.limit}`,
    params: {
      name: data.name
    }
  })
}

// 删除分类
export const deleteCategory = (id) => {
  return request({
    url: path + `/category/${id}`,
    method: 'delete'
  })
}

// 新增分类
export const saveCategory = (name) => {
  return request({
    url: path + '/category',
    method: 'post',
    params: {
      name
    }
  })
}

// 修改分类
export const updateCategory = (id, name) => {
  return request({
    url: path + `/category/${id}`,
    method: 'put',
    params: {
      name
    }
  })
}


/**
 * 标签相关接口
 */

// 标签分页查询
export const labelPageList = (data) => {
  return request({
    url: path + `/label/${data.page}/${data.limit}`,
    params: {
      name: data.name
    }
  })
}

// 新增标签
export const saveLabel = (labelName, color) => {
  return request({
    url: path + '/label',
    method: 'post',
    params: {
      labelName: labelName,
      color: color
    }
  })
}

// 获取标签
export const getLabel = (id) => {
  return request({
    url: path + `/label/${id}`,
  })
}

// 修改标签
export const updateLabel = (id, labelName, color) => {
  return request({
    url: path + `/label/${id}`,
    method: 'put',
    params: {
      labelName: labelName,
      color: color
    }
  })
}

// 删除标签
export const deleteLabel = (id) => {
  return request({
    url: path + `/label/${id}`,
    method: 'delete'
  })
}

// 批量删除标签
export const batchDelLabel = (data) => {
  return request({
    url: path + '/label/batch',
    method: 'delete',
    data
  })
}